﻿
using System.Net;

namespace CabinetGrid.DeviceDriver.Dtos
{
    public partial class MsgDto
    {
        [JsonProperty( "cmd" )]
        public string Cmd { get; init; }

        [JsonProperty( "time" )]
        public long Time { get; init; } = DateTime.Now.ToUnixTimeMilliseconds( );

        /// <summary>
        /// 数据
        /// </summary>
        [JsonProperty( "data" )]
        public Dictionary<string, object> Data { get; set; } = new Dictionary<string, object>( );

        [JsonProperty( "status" )]
        public HttpStatusCode Status { get; set; } = HttpStatusCode.OK;

        [JsonProperty( "error" )]
        public string Error { get; set; }
    }

    partial class MsgDto
    {
        public string ToJson( ) => JsonConvert.SerializeObject( this, Formatting.Indented );
    }
}
